<%
Class IndexAction 'Extends CommonAction
	Sub initialize
		Call POP_MVC.NoCache
		Call C_( Array("DB_PATH" , C_("db_dir") & S_("assignedBook")) )
		that.template.layout_on = 1
		that.template.layout_file = "Index/layout.html"
	End Sub
	
	sub index
		var_export "ccccccccccccccccc"
	
	end sub


	'显示一个工作表的所有数据
    Sub listSheet() 
	
	  dim rs,fields,sheet,book
	  book = S_("assignedBook")		'获取session中的工作簿
	  sheet = S_("assignedSheet")	'获取session中的工作表
      set rs = M_(sheet).db.onlySql(0).page(array(null,20)).select()	'按每页20条获取rs
	  set fields = M_(sheet).db.getTableFields(sheet)	'得到所有字段，Dictionary对象，键名是字段名，值是类型

	  that.assign "list",array(rs)	'以数组方式只分配当前页数据
	  that.assign "fields" , fields.keys	'分配字段名，.keys获取所有的键名，得到的是数组类型
	  that.assign "page" , P_("page")(rs).show()	'获取分页html字段串
	  that.assign "prikey" , M_(sheet).db.getPK()
	  that.display ""
    end Sub

	'显示一条记录
    Sub listRecord() 
		dim id,db,rs,fields
		id = that.get("id")
		set db = M_( S_("assignedSheet") ).db
		set rs = db.where(id).find()
		set fields = db.getTableFields("")	'getTableFields的参数传空字符串，则取当前的表名
		that.assign "data",rs
		that.assign "prikey" , M_(sheet).db.getPK()
		that.display ""
    end Sub
	
	'修改一条记录
	sub editRecord
		dim id,db,dict,fields
		id = that.get("id")
		set db = M_( S_("assignedSheet") ).db
		set dict = db.where(id).getFields("")	'getFields获取一条记录，返回的是Dictionary对象
		that.assign "data",dict
		that.assign "prikey",db.prikey
		that.display ""
	end sub
	
	sub addRecord
		dim id,db,fields
		set db = M_(S_("assignedSheet")).db
		set fields = db.getTableFields("")
		that.assign "fields",fields.keys
		that.assign "prikey",db.prikey
		that.display ""
	end sub
	
	sub update
		dim db
		set db = M_(S_("assignedSheet")).db
		if db.Save() > 0 Then
			call that.success( "修改成功" )			
		else
			call that.error("修改失败")
		end if
	end sub
	
	sub insert
		dim db
		set db = M_(S_("assignedSheet")).db
		if db.Add() > 0 Then
			call that.success( "添加成功" )			
		else
			call that.error("添加失败")
		end if
	end sub
	
	sub assignPrikey
		if isEmpty(that.form("submit")) then
			that.display ""
		else
			dim sheet,prikey
			sheet = POP_MVC.String.rtrim( that.form("sheet") , "$" )
			prikey = that.form("prikey")
			call P_("model").CreateModelFile( C_("DB_TYPE") , C_("DB_PATH") , sheet , prikey , 1 )
			call that.success( array( "主键指定成功" , U_("Assign/listSheets" )) )
		end if
	end sub
	

	
	sub deleteRecord
		set db = M_( S_("assignedSheet") ).db
		if db.where( that.get("id") ).remove()>0 Then
			call that.success( "删除成功" )			
		else
			call that.error("删除失败")
		end if
	end sub
End Class
%>